home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / TPLUS.C < prev    next >
C/C++ Source or Header  |  1992-07-10  |  12KB  |  506 lines

  1. /* TPLUS.C, (C) 1991 The Yankee Programmer
  2.    All Rights Reserved.
  3.  
  4.    This code may be distributed only when bundled with the Fractint
  5.    source code.
  6.  
  7.    Mark C. Peterson
  8.    The Yankee Programmer
  9.    405-C Queen Street, Suite #181
  10.    Southington, CT 06489
  11.    (203) 276-9721
  12.  
  13. */
  14.  
  15. #include <stdio.h>
  16. #ifndef XFRACT
  17. #include <conio.h>
  18. #include <string.h>
  19. #ifdef __TURBOC__
  20. #include <dos.h>
  21. #endif
  22. #include "port.h"
  23. #else
  24. #include "fractint.h"
  25. #endif
  26. #include "tplus.h"
  27. #include "prototyp.h"
  28.  
  29. struct TPWrite far WriteOffsets = {
  30.       0,       1,    2,     3,      0x400,   0x401,      0x402,
  31.       0x403,   0x800,    0x801,     0x802,   0x803,   0xc00,      0xc01,
  32.       0xc02,   0xc03
  33. };
  34.  
  35. struct TPRead far ReadOffsets = {
  36.       0,        2,     3,      0x400,   0x401,      0x402,
  37.       0x403,   0x800,    0x801,     0x802,   0x803,   0xc00,      0xc01,
  38.       0xc02,   0xc03
  39. };
  40.  
  41. struct _BOARD far TPlus;
  42. int TPlusErr = 0;
  43.  
  44. #ifndef XFRACT
  45.  
  46. void WriteTPWord(unsigned Register, unsigned Number) {
  47.    OUTPORTB(TPlus.Write.INDIRECT, Register);
  48.    OUTPORTW(TPlus.Write.WBL, Number);
  49. }
  50.  
  51. void WriteTPByte(unsigned Register, unsigned Number) {
  52.    OUTPORTB(TPlus.Write.INDIRECT, Register);
  53.    OUTPORTB(TPlus.Write.WBL, Number);
  54. }
  55.  
  56. unsigned ReadTPWord(unsigned Register) {
  57.    OUTPORTB(TPlus.Write.INDIRECT, Register);
  58.    return(INPORTW(TPlus.Read.RBL));
  59. }
  60.  
  61. BYTE ReadTPByte(unsigned Register) {
  62.    OUTPORTB(TPlus.Write.INDIRECT, Register);
  63.    return((BYTE)INPORTB(TPlus.Read.RBL));
  64. }
  65.  
  66. void DisableMemory(void) {
  67.    unsigned Mode1;
  68.  
  69.    Mode1 = INPORTB(TPlus.Read.MODE1);
  70.    Mode1 &= 0xfe;
  71.    OUTPORTB(TPlus.Write.MODE1, Mode1);
  72. }
  73.  
  74. void EnableMemory(void) {
  75.    unsigned Mode1;
  76.  
  77.    Mode1 = INPORTB(TPlus.Read.MODE1);
  78.    Mode1 |= 1;
  79.    OUTPORTB(TPlus.Write.MODE1, Mode1);
  80. }
  81.  
  82. struct TPLUS_IO {
  83.    unsigned Cmd;
  84.    int Initx, Finalx, Inity, Finaly, Destx, Desty;
  85.    unsigned long Color;
  86.    unsigned RegsOffset, RegsSegment, RegListOffset, RegListSegment,
  87.         BoardNumber, StructSize;
  88. } far TPlusIO;
  89.  
  90. #include <dos.h>
  91.  
  92. /* TARGAP.SYS Commands */
  93. #define READALL    0
  94. #define WRITEALL   0
  95. #define NUMBOARDS  3
  96. #define FILLBLOCK  4
  97. #define GRABFIELD  4
  98. #define RESET       5
  99. #define GRABFRAME  5
  100. #define WAITFORVB  6
  101. #define SETBOARD   8
  102. #define IOBASE       9
  103.  
  104. /* DOS IO Commands */
  105. #define DOS_READ   0x4402
  106. #define DOS_WRITE  0x4403
  107.  
  108. int hTPlus = -1;
  109. unsigned NumTPlus = 0;
  110.  
  111. int TargapSys(int Command, unsigned DOS) {
  112.    struct TPLUS_IO far *IOPtr;
  113.    unsigned far *RegPtr;
  114.    union REGS r;
  115.    struct SREGS s;
  116.  
  117.    if(hTPlus != -1) {
  118.       r.x.ax = DOS;
  119.       r.x.bx = hTPlus;
  120.       r.x.cx = sizeof(TPlusIO);
  121.       IOPtr = &TPlusIO;
  122.       RegPtr = TPlus.Reg;
  123.       r.x.dx = FP_OFF(IOPtr);
  124.       s.ds = FP_SEG(IOPtr);
  125.       TPlusIO.Cmd = Command;
  126.       TPlusIO.StructSize = sizeof(TPlus.Reg);
  127.       TPlusIO.RegsOffset = FP_OFF(RegPtr);
  128.       TPlusIO.RegsSegment = FP_SEG(RegPtr);
  129.       intdosx(&r, &r, &s);
  130.       return(!r.x.cflag);
  131.    }
  132.    return(0);
  133. }
  134.  
  135. int _SetBoard(int BoardNumber) {
  136.    TPlusIO.BoardNumber = BoardNumber;
  137.    return(TargapSys(SETBOARD, DOS_WRITE));
  138. }
  139.  
  140. #include <stdio.h>
  141.  
  142. int TPlusLUT(BYTE far *LUTData, unsigned Index, unsigned Number,
  143.              unsigned DosFlag)
  144. {
  145.    struct TPLUS_IO far *IOPtr;
  146.    union REGS r;
  147.    struct SREGS s;
  148.  
  149.    if(hTPlus != -1) {
  150.       r.x.ax = DosFlag;
  151.       r.x.bx = hTPlus;
  152.       r.x.cx = sizeof(TPlusIO);
  153.       IOPtr = &TPlusIO;
  154.       r.x.dx = FP_OFF(IOPtr);
  155.       s.ds = FP_SEG(IOPtr);
  156.       TPlusIO.Cmd = 9;
  157.       TPlusIO.StructSize = sizeof(TPlus.Reg);
  158.       TPlusIO.RegsOffset = FP_OFF(LUTData);
  159.       TPlusIO.RegsSegment = FP_SEG(LUTData);
  160.       TPlusIO.BoardNumber = Number;
  161.       TPlusIO.RegListOffset = Index;
  162.       intdosx(&r, &r, &s);
  163.       return(!r.x.cflag);
  164.    }
  165.    return(0);
  166. }
  167.  
  168. int SetVGA_LUT(void) {
  169.    char PathName[80];
  170.    FILE *Data;
  171.    BYTE LUTData[256 * 3];
  172.  
  173.    findpath("tplus.dat", PathName);
  174.    if(PathName[0]) {
  175.       if((Data = fopen(PathName, "rb")) != 0) {
  176.      if(!fseek(Data, 16L << 8, SEEK_SET)) {
  177.         if(fread(LUTData, 1, sizeof(LUTData), Data) == sizeof(LUTData)) {
  178.            fclose(Data);
  179.            return(TPlusLUT(LUTData, 0, sizeof(LUTData), DOS_WRITE));
  180.         }
  181.      }
  182.       }
  183.    }
  184.    if(Data > 0)
  185.       fclose(Data);
  186.    return(0);
  187. }
  188.  
  189. int SetColorDepth(int Depth) {
  190.    if(TPlus.Reg[HIRES] && Depth == 4)
  191.       Depth = 2;
  192.    switch(Depth) {
  193.       case 1:
  194.      if(TPlus.Reg[XDOTS] > 512) {
  195.         TPlus.Reg[PERM] = 1;
  196.         TPlus.Reg[BYCAP] = 3;
  197.         TPlus.RowBytes = 10;
  198.      }
  199.      else {
  200.         TPlus.Reg[PERM] = 0;
  201.         TPlus.Reg[BYCAP] = 1;
  202.         TPlus.RowBytes = 9;
  203.      }
  204.      TPlus.Reg[BUFFPORTSRC] = 0;
  205.      TPlus.Reg[CM1] = 0;
  206.      TPlus.Reg[CM2] = 0;
  207.      TPlus.Reg[DEPTH] = 1;
  208.      TPlus.Reg[LIVE8] = 1;
  209.      TPlus.Reg[DISPMODE] = 0;
  210.      TPlus.Reg[LIVEPORTSRC] = 1;
  211.      TPlus.Reg[LUTBYPASS] = 0;
  212.      break;
  213.       case 2:
  214.      if(TPlus.Reg[XDOTS] > 512) {
  215.         TPlus.Reg[PERM] = 3;
  216.         TPlus.Reg[BYCAP] = 15;
  217.         TPlus.Reg[CM2] = 1;
  218.         TPlus.RowBytes = 11;
  219.      }
  220.      else {
  221.         TPlus.Reg[PERM] = 1;
  222.         TPlus.Reg[BYCAP] = 3;
  223.         TPlus.Reg[CM2] = 0;
  224.         TPlus.RowBytes = 10;
  225.      }
  226.      TPlus.Reg[BUFFPORTSRC] = 1;
  227.      TPlus.Reg[CM1] = 0;
  228.      TPlus.Reg[DEPTH] = 2;
  229.      TPlus.Reg[LIVE8] = 0;
  230.      TPlus.Reg[DISPMODE] = 0;
  231.      TPlus.Reg[LIVEPORTSRC] = 1;
  232.      TPlus.Reg[LUTBYPASS] = 1;
  233.      break;
  234.       case 3:
  235.       case 4:
  236.      TPlus.Reg[PERM] = (Depth == 3) ? 2 : 3;
  237.      TPlus.Reg[BYCAP] = 0xf;
  238.      TPlus.Reg[BUFFPORTSRC] = 3;
  239.      TPlus.Reg[CM1] = 1;
  240.      TPlus.Reg[CM2] = 1;
  241.      TPlus.Reg[DEPTH] = 4;
  242.      TPlus.Reg[LIVE8] = 0;
  243.      TPlus.Reg[DISPMODE] = 0;
  244.      TPlus.Reg[LIVEPORTSRC] = 1;
  245.      TPlus.Reg[LUTBYPASS] = 1;
  246.      TPlus.RowBytes = 11;
  247.      break;
  248.       default:
  249.      return(0);
  250.    }
  251.    TPlus.Plot = WriteTPlusBankedPixel;
  252.    TPlus.GetColor = ReadTPlusBankedPixel;
  253.    TPlus.Reg[LIVEMIXSRC] = 0;
  254.    TPlus.Reg[CM3] = 1;
  255.    TPlus.RowsPerBank = 16 - TPlus.RowBytes;
  256.    if(TargapSys(WRITEALL, DOS_WRITE)) {
  257.       if(Depth == 1)
  258.      SetVGA_LUT();
  259.       if(TPlus.ClearScreen)
  260.      ClearTPlusScreen();
  261.       TargapSys(READALL, DOS_READ);
  262.       return(Depth);
  263.    }
  264.    return(0);
  265. }
  266.  
  267. int SetBoard(int BoardNumber) {
  268.    unsigned ioBase, n;
  269.    unsigned long MemBase;
  270.  
  271.    if(TPlus.ThisBoard != -1)
  272.       DisableMemory();
  273.    if(!_SetBoard(BoardNumber))
  274.       return(0);
  275.    if(!TargapSys(READALL, DOS_READ))
  276.       return(0);
  277.    TPlus.VerPan       = TPlus.Reg[VPAN];
  278.    TPlus.HorPan       = TPlus.Reg[HPAN];
  279.    TPlus.Top          = TPlus.Reg[TOP];
  280.    TPlus.Bottom       = TPlus.Reg[BOT];
  281.    TPlus.Bank64k      = 0xffff;         /* Force a bank switch */
  282.  
  283.    MemBase      = TPlus.Reg[MEM_BASE];
  284.    MemBase += (TPlus.Reg[MEM_MAP] != 3) ? 8 : 0;
  285.    TPlus.Screen = (BYTE far *)(MemBase << 28);
  286.  
  287.    if(!TargapSys(IOBASE, DOS_READ))
  288.       return(0);
  289.    ioBase = TPlusIO.BoardNumber;
  290.    TPlus.Read = ReadOffsets;
  291.    TPlus.Write = WriteOffsets;
  292.    for(n = 0; n < sizeof(TPlus.Read) / sizeof(unsigned); n++)
  293.       ((unsigned far *)&(TPlus.Read))[n] += ioBase;
  294.    for(n = 0; n < sizeof(TPlus.Write) / sizeof(unsigned); n++)
  295.       ((unsigned far *)&(TPlus.Write))[n] += ioBase;
  296.  
  297.    EnableMemory();
  298.    return(1);
  299. }
  300.  
  301. int ResetBoard(int BoardNumber) {
  302.    int CurrBoard, Status = 0;
  303.  
  304.    CurrBoard = TPlus.ThisBoard;
  305.    if(_SetBoard(BoardNumber))
  306.       Status = TargapSys(RESET, DOS_WRITE);
  307.    if(CurrBoard > 0)
  308.       _SetBoard(CurrBoard);
  309.    return(Status);
  310. }
  311.  
  312. #include <fcntl.h>
  313. #include <io.h>
  314.  
  315. int CheckForTPlus(void) {
  316.    unsigned n;
  317.  
  318.    if((hTPlus = open("TARGPLUS", O_RDWR | O_BINARY )) != -1) {
  319.       if(!TargapSys(NUMBOARDS, DOS_READ))
  320.      return(0);
  321.       NumTPlus = TPlusIO.BoardNumber;
  322.       TPlus.ThisBoard = -1;
  323.       TPlus.ClearScreen = 1;
  324.       for(n = 0; n < NumTPlus; n++)
  325.      if(!ResetBoard(n))
  326.         return(0);
  327.       if(SetBoard(0))
  328.      return(1);
  329.    }
  330.    return(0);
  331. }
  332.  
  333. int SetTPlusMode(int Mode, int NotIntFlag, int Depth, int Zoom) {
  334.    unsigned n;
  335.    char PathName[80];
  336.    FILE *Data;
  337.    unsigned NewRegs[128];
  338.  
  339.    findpath("tplus.dat", PathName);
  340.    if(PathName[0]) {
  341.       if((Data = fopen(PathName, "rb")) != 0) {
  342.      if(!fseek(Data, (lon